package com.example.wtx.generator;


import com.example.wtx.generator.service.GeneratorService;
import com.example.wtx.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sys")
public class GeneratorController {

    @Autowired
    MyCodeGenerator myCodeGenerator;

    @Autowired
    GeneratorService generatorService;

    @PostMapping("/generator")
    public R generator(@RequestBody SysConfigVo sysConfigVo){
        myCodeGenerator.execute(sysConfigVo);
        return R.ok();
    }
    @GetMapping("/tableNames")
    public R getTableName(){
        List<String> tableNames = generatorService.getTableNames();
        List<Table> list = new ArrayList<>();
        Table temptable = null;
        for (int i = 0;i < tableNames.size();i++){
            temptable = new Table();
            temptable.setId(i);
            temptable.setTableName(tableNames.get(i));
            list.add(temptable);
        }
        return R.ok(list);
    }


}
